﻿<UserControl x:Class="Infrastructure.Views.DynamicListView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewModels="clr-namespace:Infrastructure.ViewModels"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:t="clr-namespace:Infrastructure.Theming"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:tr="clr-namespace:Infrastructure.Triggers"
    xmlns:mvvm="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL5"
    xmlns:converters="clr-namespace:Infrastructure.Converters"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400"
    d:DataContext="{d:DesignInstance d:Type=viewModels:DynamicListViewModel}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Infrastructure.Client;component/Assets/Themes/DefaultTheme.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <converters:DynamicListViewRowLoadingConverter x:Key="RowLoadingConverter" />
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Border t:Theme.Style="{StaticResource TitleBorder}">
            <TextBlock Text="{Binding Title}" t:Theme.Style="{StaticResource TitleText}" />
        </Border>
        <ContentControl Grid.Row="1" Content="{Binding Filter}" Margin="10" />
        <sdk:DataGrid Grid.Row="2" ItemsSource="{Binding Items}" Margin="10" IsReadOnly="True" SelectionMode="Single" SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="AutoGeneratingColumn" >
                    <tr:TranslateColumnHeader />
                    <tr:FormatDateTimeColumn />
                    <tr:SetImplicitColumnTemplate />
                </i:EventTrigger>
                <i:EventTrigger EventName="LoadingRow">
                    <mvvm:EventToCommand 
                        Command="{Binding LoadListViewItemsCommand}" 
                        PassEventArgsToCommand="True" 
                        EventArgsConverter="{StaticResource RowLoadingConverter}" 
                        EventArgsConverterParameter="{Binding}" />
                </i:EventTrigger>
                <tr:DoubleClickTrigger HandledEventsToo="True" >
                    <mvvm:EventToCommand Command="{Binding OpenDetailsCommand}" CommandParameter="{Binding DetailsViewUri}" />
                </tr:DoubleClickTrigger>
            </i:Interaction.Triggers>
        </sdk:DataGrid>
    </Grid>
</UserControl>
